package com.crossdomain.common;

import java.util.HashMap;
import java.util.Map;



/**
 * @author jannal 2016-01-13
 */
@SuppressWarnings("unchecked")
public class RequestJsonToBean {

    /**
     * 将客户端传过来的json串中的params转成实际的对象
     * 
     * @param json
     * @param clazz
     * @return
     * @throws TransformJsonParamsException
     */
    public static <T> T requestJsonToBean(String json, Class<T> clazz)  {
        if (null == json || "".equals(json)) {
            return null;
        }
        Map<String, Class<?>> classMap = new HashMap<String, Class<?>>(2);
        classMap.put("params", clazz);
        try {
            ControllerRequestBody<T> controllerRequestBody = JsonUtils.json2Obj(json, ControllerRequestBody.class, classMap);
            T params = controllerRequestBody.getParams();
            return params;
        } catch (Exception e) {
            throw new RuntimeException("请求参数解析错误,json数据是:" + json);
        }
    }
}
